import { Component, OnInit } from '@angular/core';
import { AuthGuardService } from '../@core/auth-guard-service.guard';
import { GetCollectionService } from '../@core/get-collection.service'

@Component({
  selector: 'app-market',
  templateUrl: './market.component.html',
  styleUrls: ['./market.component.scss']
})
export class MarketComponent implements OnInit {
  queryParams = {
    page: 1,
    pageSize: 10,
    collectionStatus: -1
  }
  collectionList = []
  totalNum = 0
  pageSizeOptions = [10, 20, 30, 40, 50]

  constructor(
    private authGuardService: AuthGuardService,
    private getCollectionService: GetCollectionService) { }

  ngOnInit(): void {
    this.getList()
  }

  getList() {
    this.authGuardService
      .collectionDetail(this.queryParams)
      .subscribe((res) => {
        if (res.code === 0) {
          this.totalNum = res.data.totalNum
          this.collectionList = res.data.collection
        }
      })
  }

  pageSizeChange(pageSize) {
    this.queryParams.pageSize = pageSize
    this.pageIndexChange(1)
  }

  pageIndexChange(pageIndex) {
    this.queryParams.page = pageIndex
    this.getList()
  }

  callGetList() {
    this.getList()
  }

  applyCollecti(collection) {
    this.getCollectionService.openPublishDialog(collection)
  }
}
